/*二分查找*/
/*
#include <stdio.h>
#include <stdlib.h>

#define MAXSIZE 10
#define NotFound 0
typedef int ElementType;

typedef int Position;
typedef struct LNode *List;
struct LNode {
    ElementType Data[MAXSIZE];
    Position Last;  保存线性表中最后一个元素的位置 
};

List ReadInput();  裁判实现，细节不表。元素从下标1开始存储
Position BinarySearch( List L, ElementType X );

int main()
{
    List L;
    ElementType X;
    Position P;

    L = ReadInput();
    scanf("%d", &X);
    P = BinarySearch( L, X );
    printf("%d\n", P);

    return 0;
}

//你的代码将被嵌在这里 */

//完成
Position BinarySearch( List L, ElementType X ) {
    Position right = L->Last;
    Position left = 1;
    while (left <= right) {
        Position mid = (Position)(left + (right - left) / 2);
        if (L->Data[mid] == X) {
            return mid;
        } else if (L->Data[mid] > X) {
            right = mid-1;
        } else {
            left = mid+1;
        }
    }
    return NotFound ;
}
// Position cal(List L, Position left, Position right, ElementType X) {
//     if (left <= right) {
//         Position mid = (Position)(left + (right - left) / 2);
//         if (L->Data[mid] == X) {
//             return mid;
//         } else if (L->Data[mid] > X) {
//             return cal(L, left, mid - 1, X);
//         } else {
//             return cal(L, mid + 1, right, X);
//         }
//     }
//     return NotFound;
    
// }
// Position BinarySearch( List L, ElementType X ) {
//     Position c = cal(L, 1, L->Last, X);
//     return c;
// }